//
//  CampusDetailPreviewViewCell.m
//  ShowYork
//
//  Created by hxh on 2021/3/26.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusDetailPreviewViewCell.h"

@interface CampusDetailPreviewViewCell ()
@property (nonatomic,strong)UIImageView *previewImgView;
@property (nonatomic,strong)UIImageView *videoIcon;
@property (nonatomic,strong)UIButton *coverBtn;
@end

@implementation CampusDetailPreviewViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.previewImgView = [[UIImageView alloc]init];
    self.previewImgView.layer.cornerRadius = 8;
    self.previewImgView.layer.masksToBounds = YES;
    self.previewImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.previewImgView.backgroundColor = RGBA(240, 240, 240, 1);
    [self.contentView addSubview:self.previewImgView];
    [self.previewImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.right.equalTo(self.contentView).offset(-20);
        make.height.mas_equalTo((kScreenW - 40)/16*9.0).priorityHigh();
        make.bottom.equalTo(self.contentView);
        make.top.equalTo(self.contentView);
    }];
    self.videoIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"campus_video_tag"]];
    self.videoIcon.hidden = YES;
    [self.contentView addSubview:self.videoIcon];
    [self.videoIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
    }];

    self.coverBtn = [[UIButton alloc]init];
    [self.coverBtn addTarget:self action:@selector(coverMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"CampusDetailPreviewViewCell";
    CampusDetailPreviewViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CampusDetailPreviewViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (void)setItemModel:(CampusSchoolDescModel *)itemModel{
    _itemModel = itemModel;
    if (itemModel.advertisementType.intValue == 1) {
        self.videoIcon.hidden = YES;
    }else{
        self.videoIcon.hidden = NO;
    }
    [self.previewImgView sd_setImageWithURL:[NSURL URLWithString:itemModel.advertisementCover]];
}
- (void)coverMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showPreviewVideo)] && self.itemModel.advertisementType.intValue == 2) {
        [self.delegate showPreviewVideo];
    }
    if (self.delegate && [self.delegate respondsToSelector:@selector(showPreviewPicture)] && self.itemModel.advertisementType.intValue == 1) {
        [self.delegate showPreviewPicture];
    }
}
@end
